<?php
/*************************************************

广告模块公共控制器 - the 
Author: WangHuabin <17-5-27>

*************************************************/
namespace Home\Controller;
use Think\Controller;
class AdController extends Controller {

    public function get_ad($tag){
        //获取广告位
        $map['tag'] = $tag;
        $position = D('AdPosition')->get_one($map);
        //查询广告信息
        $map = array();
        $map['pid'] = $position['id'];
        $data = D('AdInfo')->get_all($map);
        
        return $data;
    }

    //獲取廣告接口
    public function ad_info(){
        $tag = I('get.tag');
        $ad_info = $this->get_ad($tag);
        foreach ($ad_info as $k => $v) {
            $str = $v['content'];
            $ad_info[$k]['content'] = preg_replace ('/http:\/\//', 'https://', $str,1);
        }
        if($ad_info){
            $res['errorCode'] = 1;
            $res['data'] = $ad_info;
        }else{
            $res['errorCode'] = 0;
        }
                $this->ajaxReturn($res);
    }

}